﻿using MediatR;
using W.Purchase.API.Application.Command.PayableCommand;
using W.Purchase.Repository.Impl;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler.PayableCommandHandler
{
    public class PayableDelCommandHandler:IRequestHandler<PayableDelCommand,int>
    {
        private readonly IPayableRepository _ipayableRepository;
        public PayableDelCommandHandler(IPayableRepository ipayableRepository)
        {
            _ipayableRepository = ipayableRepository;
        }

        public async Task<int> Handle(PayableDelCommand request, CancellationToken cancellationToken)
        {
            var list = await _ipayableRepository.GetAllAsaync();
            var plist = list.Where(c => c.PayableId == request.PayableId).FirstOrDefault();
            if (plist != null)
            {
                plist.IsDelete = true;
            }
            return await _ipayableRepository.Update(plist);
        }
    }
}
